home *** CD-ROM | disk | FTP | other *** search
-
- MCI.VBX - Playing background sound files
-
- This small program demonstrates a method of playing
- midi files in the background using the MCI.VBX custom
- control supplied with Visual Basic 3.0 professional. The
- MCI control is invisible to the user at all times.
- The program uses the done event of the MCI custom
- control to play a sequence of midi files. Options include
- disabling sound, skipping a file, and enabling sound. The
- current midi file being played is displayed on the bottom
- line of the Sound menu option.
- When the opening form loads, code in the load event
- sets the Sound menu options, initialises a variable "i" to
- 0, sets the first file name to be played and calls the
- Midiplay proceedure from the MCI.Bas file.
- When this file has finished playing, a "done" event is
- generated by the MCI custom control. The variable "i" is
- incremented to 1, which is then processed by the Select
- Case structure, which plays the midi file named in Case 1.
- When this file is finished playing, another "done" event
- occurs, the variable "i" is incremented to 2 and the file
- named in Case 2 plays. In this manner the "done" event
- cycles through the Select Case structure. The last select
- case option (4) replays the first midi file which started
- the cycle, and resets the "i" variable to 0. This plays
- the second midi file in the cycle when the "done" event
- fires.
- The Select Case Else option is used to end the cycle.
- On the Disable Sound menu, "i" is set to 20, which
- triggers the Select Case Else option, which closes the MCI
- control if it is playing.
- The Enable Sound option from the sound menu starts the
- cycle over again.
- The Midiplay proceedure includes code that tests the
- MCI_PLAYING_MODE. If the user does not have a sound card
- installed in his computer or properly configured for use
- with Windows, a VB error event will not occur crashing
- the program but the the Sound options in the menu are
- all greyed out and the string "Midi File: None" appears at
- the bottom of the menu.
- I used the global constants for MCI supplied with the
- sample .mak file "Mcitest.mak"(global.bas) which came
- with Visual Basic. The MCI_PLAYING_MODE statement requires
- them.
- Note that the form1 Unload event contains code to close
- the MMControl if it is open when you exit the program.
- Although this example uses only Midi files and the Midi
- file sequencer, the examples could easily be changed to
- play Wave files instead by opening the MCI control as a
- Wave player and changing all the Midi files to Wave files.
-
- In my opinion, the MCI.VBX custom control is very
- poorly documented in the Visual Basic manual. The only
- .mak example given shows how to play one sound file at
- a time, by loading a single file from disk, and uses only
- the click events associated with the MMControl to
- manipulate the file. There is some sample code to load a
- single sound file in a form's load event - but no clue as
- to how to process multiple sound files without requiring
- the program's user to either manually load a file or click
- on the VCR type control.
- This may not be an optimal way of manipulating the
- MCI.vbx custom control but it works! I've used it in
- several applications to play background sound files and it
- performs flawlessly. If anyone knows of a better way to do
- this, I would appreciate hearing about it. I'm a beginner
- still learning VB.
-